<!DOCTYPE html>
<html>
<head>

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-responsive.min.css">

<style type="text/css">
.nav { }
.nav li { float: left; width: 110px; }
.container { background-color: #ffffff; padding: 30px; }
.content { padding: 30px; }
body, h1, h2, h3, h4 { font-family: "Trebuchet MS","Helvetica Neue",Arial,Helvetica,sans-serif,"Georgia";}
body { background-color: #eeeeee; }
header { width: 100%; }
blockquote p { font-size: 14px; }
</style>
<title>ZPar | TWeb Wrapper: ZPar Support for the Neural Network Tagger</title>
</head>

<body>
<div class="table-bordered container">
<div class="content">

<header>
<div class="page-header text-center">
<h1>TWeb Wrapper: ZPar Support for the Neural Network Tagger</h1>
</div>
</header>


<h2><a id="sec:overview">Overview</a></h2>
<p>
This is the zpar wrapper for <a href="https://github.com/majineu/TWeb">TWeb</a>, the robust web tagger using neural network.
</p>

<h2><a id="How-to-compile">How to compile</a></h2>

<p>
Suppose that ZPar has been downloaded to the directory <code>zpar</code>. 
The TWeb source is already inlcuded and located in <code>zpar/src/common/tagger/implementations/tweb/TWeb</code>.
To make a POS tagging system using TWeb, 
change the GENERIC_TAGGER_IMPL macro defined in <code>Makefile</code> into <code>tweb</code>,
and type <code>make postagger</code>. 
This will create a directory <code>zpar/dist/postagger</code>, in which there are two files: <code>train</code> and <code>tagger</code>. 
The file <code>train</code> is used to train a tagging model,and the file <code>tagger</code> is used to tag new texts using a trained tagging model.
</p>

<h2><a id="Format-of-inputs-and-outputs">Format of inputs and outputs</a></h2>
<p>
The input files to the <code>tagger</code> executable are formatted as a sequence of tokenized English sentences. An example input is:
</p>
<pre><code> Ms. Haag plays Elianti .</code></pre>

<p>
The output files contain space-separated words:
</p>
<pre><code> Ms./NNP Haag/NNP plays/VBZ Elianti/NNP ./.</code></pre>

<p>
The format of training files for the <code>train</code> executable is <strong>quite different</strong> from other tagger implementations in zpar,
the details will be given in the next section.
</p>

<h2><a id="sec:how-train-model">How to train a model</a></h2>
<p>
To train a model, use
</p>
<pre><code> zpar/dist/postagger/train training &lt;configureFile&gt; </code></pre>

<p>
Which is the same with the original TWeb.
</p>
<p>
For details about configureFile and training data format, please refer to
the <a href="https://raw.githubusercontent.com/majineu/TWeb/master/readme.txt">TWeb README</a>.
A copy is included as follows.
</p>

<pre><code>
1. Build.
  Go into the src dir then make.
    a. cd src
    b. make -f Makefile
  After make, an executable named Tagger would be created in src/


2. Training.
  You can train your own model with the following command:
     src/Tagger   training   configureFile
  for example:
     src/Tagger  training  config/conf_sample.txt   
  where configFile specify some of the parameters used during training.
  There are some examples of the configureFile in config/
  (When training your own model, you just need to specify the path of the training set, 
   development set and the path of the trained model.
   For others parameters, use their default value is OK)

  lines start with :: will be ignored
  Take conf/conf.txt as an example:
    trainPath    : specify the training data
    devPath      : specify the development set, you can specify several development set
    testPath     : similar as devPath.
    strLogDir    : a log file will be generated during the training process,
                     the log file records tagging accuracy of each epoch on development and test sets.
    strModelPath : specify the directory where the model will be generated
    nRound       : number of maximum training epoch.
    prefix       : the prefix of the name of the trained model
    strRBMPrefix : specify the "common prefix" of the word-representation RBM, 
                     which is used as features to improve tagging accuracy.
                   
                     Example of "common Prefix":
                     WRRBM contains several modules, for example:
                      wrrbm_abc.dict  wrrbm_abc.model  wrrbm_abc.random
                     the common prefix is "wrrbm_abc".
                   using WRRBM will cause both training and testing slow,
                   but the model will improve web-domain tagging accuracy.

                   if you want to train a tagger on standard WSJ data set,
                   you can choose to ignore wrrbm by add "::" at the begining
                   of the line of this parameter.

    bEnTagger    : "true" denotes English tagger, 
                   "false" means Chinese tagger(currently not supported)
    bEarlyUpdate : "true" denotes whenever a word is incorrectly tagged,
                    parameters will be updated and the rest of the sentence is ignored.
    
    fMargin      : since we use a margin loss (Ma et al., 2014) to train the model, 
                   this parameter specify the value of the margin
    fRate        : learning rate, currently, we do not use weight decay.
    vIHSize      : size of the feature embedding, corresponding to the deminsion of the hidden layer size of
                   the sparse feature module described in section 3.2 of (Ma et al., 2014)
    vIHType      : "linear", linear projection layer


3. Tagging
    src/Tagger  tagging  modelPrefix  inputFile  outputFile
    
    After training, several files will be generated at the location specified by
    "strModelPath", these files share a common prefix, for example:
    
    WebTagger_AvgParam.confg   WebTagger_AvgParam.model  ....
    the common prefix is "WebTagger_AvgParam"

    "modelPrefix" is that common prefix.


Data format:
  See the sample data provided at sampleData/.

  Each line of the data file is a token which contains three columns, 
     Word  generalizedForm  POS
  Word: word form
  generalizedForm: lower cased Word, digit are converted to #DIG...
                   scripts for such processing will coming soon.
  POS: part of speech, when tagging new data, this column would be ignored by the tagger  
  A sentence contains several tokens.  Sentences are separated by empty line.
  

How to cite:
  Either cite the URL or the paper 
  "Tagging the web: building robust web tagger using neural network"
  is OK.
</code></pre>

<p>
Example configuration files and data set can be found in <code>config</code> and <code>sampleData</code>
under <code>zpar/src/common/tagger/implementations/tweb/TWeb</code>.
</p>

<h2><a id="How-to-tag-new-texts">How to tag new texts</a></h2>
<p>
To apply an existing model to tag new texts, use
</p>
<pre><code> zpar/dist/postagger/tagger &lt;modelPrefix&gt; &lt;input-file&gt; &lt;output-file&gt;</code></pre>

<p>
The modelPrefix is the same as described in TWeb README.
</p>
<p>
For example, using the model we just trained, we can tag <a href="eng_pos_files/input.txt">an example input</a> by
</p>
<pre><code> zpar/dist/postagger/tagger modelPrefix input.txt output.txt</code></pre>

<p>
The output file contains automatically tagged sentences.
</p>

<h2><a id="reference">Reference</a></h2>
<ul>
<li>
 Ji Ma, Yue Zhang and Jingbo Zhu. 2014. Tagging The Web: Building A Robust Web Tagger with Neural Network. In <em>Proc. of ACL</em>, 144--154.
</li>
</ul>

</div>
</div>
<footer class="text-center">
<p>
ZPar Release 0.7
</p>
</footer>
</body>
</html>
